//
//  VKMeJiFenController.m
//  V-Learn
//
//  Created by liubo on 2019/1/9.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKReManagerController.h"
#import "VKReManagerChildController.h"
#import "VKReNextLevelController.h"
#import "VKReManagerCashController.h"
@interface VKReManagerController ()<ZJScrollPageViewDelegate>
@property(strong, nonatomic)NSMutableArray<NSString *> *titles;
@property(strong, nonatomic)NSMutableArray<NSString *> *ids;

@property(strong, nonatomic)NSArray<UIViewController *> *childVcs;
@property (nonatomic, strong) ZJScrollPageView *scrollPageView;
@end

@implementation VKReManagerController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"推荐管理";
    self.view.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:self.jiFenShopCollectionView];
    [self setupDataArray];
    
    self.edgesForExtendedLayout = @[];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self setupUI];

    [self setupScrollView];
}
- (void)setupScrollView{
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    //显示滚动条
    style.showLine = YES;
    style.scrollLineColor = [UIColor cz_colorWithRed:39 green:133 blue:197];
    style.scrollLineHeight = 1.5;
    style.scaleTitle = NO;
    //    style.scrollTitle = NO;
    style.autoAdjustTitlesWidth = YES;
    style.titleFont = [UIFont systemFontOfSize:16];
    style.normalTitleColor = [UIColor cz_colorWithRed:103 green:103 blue:103];
    style.selectedTitleColor = [UIColor cz_colorWithRed:40 green:40 blue:40];
    style.titleMargin = 30;
    // 颜色渐变
    style.gradualChangeTitleColor = YES;
    _titles = @[@"收入记录",@"提现记录"].mutableCopy;
    // 初始化
    self.scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0, 285, self.view.bounds.size.width, [UIScreen cz_screenHeight] - 285) segmentStyle:style titles:self.titles parentViewController:self delegate:self];
    [self.view addSubview:self.scrollPageView];
//    self.scrollPageView.extraBtnOnClick = ^(UIButton *extraBtn) {
//        NSLog(@"%ld%@",extraBtn.tag,extraBtn.currentTitle);
//    };
}

//  以下
- (NSInteger)numberOfChildViewControllers {
    return self.titles.count;
}

- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    UIViewController<ZJScrollPageViewChildVcDelegate> *childVc = reuseViewController;
    
    if (!childVc) {
        childVc = [[VKReManagerChildController alloc] init];
        
    }

//    NSLog(@"%ld-----%@",(long)index, childVc);
    [[NSUserDefaults standardUserDefaults] setObject:@(index) forKey:@"EarnRecordIndex"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return childVc;
}


- (BOOL)shouldAutomaticallyForwardAppearanceMethods {
    return NO;
}

- (void)setupUI{
    //bg-integral@2x

    UIImageView *imageV = [[UIImageView alloc] init];
    [self.view addSubview:imageV];
    imageV.userInteractionEnabled = YES;
    imageV.image = [UIImage imageNamed:@"bg-2"];
    imageV.contentMode = UIViewContentModeScaleAspectFill;
    imageV.clipsToBounds = YES;
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(@0);
        make.height.equalTo(@265);
    }];
    
    UIImageView *circleImageV = [[UIImageView alloc] init];
    [self.view addSubview:circleImageV];
    circleImageV.userInteractionEnabled = YES;
    circleImageV.image = [UIImage imageNamed:@"bg-c2"];
    circleImageV.contentMode = UIViewContentModeScaleAspectFill;
    circleImageV.clipsToBounds = YES;
    [circleImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(imageV);
        make.height.width.equalTo(@120);
    }];

    UILabel *titleLabel = [[UILabel alloc]init];
    [imageV addSubview:titleLabel];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.text = @"推荐管理";
    titleLabel.font = [UIFont systemFontOfSize:17];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(imageV);
        make.bottom.mas_equalTo(circleImageV.mas_top).offset( -10);
    }];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"下级" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    [imageV addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@30);
        make.width.equalTo(@40);
        make.centerY.equalTo(titleLabel);
        make.right.mas_equalTo(-15);
    }];
    [button addTarget:self action:@selector(buttonItemClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn.backgroundColor = [UIColor clearColor];
    [imageV addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@12);
        make.width.height.equalTo(@40);
        make.centerY.equalTo(titleLabel);
    }];
    UIImageView *imageBackV = [[UIImageView alloc]init];
    [btn addSubview:imageBackV];
    imageBackV.image = [UIImage imageNamed:@"back-white"];
    imageBackV.contentMode = UIViewContentModeScaleAspectFill;
    imageBackV.userInteractionEnabled = NO;
    [imageBackV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(titleLabel);
        make.centerX.equalTo(btn);
    }];
    [btn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];

    UILabel *countLabel = [[UILabel alloc]init];
    [circleImageV addSubview:countLabel];
    countLabel.textColor = [UIColor cz_colorWithRed:39 green:133 blue:197];
    NSString *earnPrice  = [UserModel getUserModel].earnPrice;

    [self downCountAttributedleftString:@"¥" withRightString:earnPrice withLabel:countLabel];
//    countLabel.font = [UIFont systemFontOfSize:20];
    
    [countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(circleImageV);
    }];
    
    UIButton *liBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    liBtn.backgroundColor = [UIColor clearColor];
    liBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [liBtn setTitle:@"申请提现" forState:UIControlStateNormal];
    [imageV addSubview:liBtn];
    liBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    liBtn.layer.borderWidth = 1;
    liBtn.layer.masksToBounds = YES;
    liBtn.layer.cornerRadius = 4;
    [liBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(imageV.mas_bottom).offset(-20);
        make.width.equalTo(@85);
        make.height.equalTo(@26);
        make.centerX.equalTo(imageV);
    }];
    [liBtn addTarget:self action:@selector(liBtnClick) forControlEvents:UIControlEventTouchUpInside];

}
- (void)downCountAttributedleftString:(NSString *)leftString withRightString:(NSString *)rightString withLabel:(UILabel *)contentLabel {
    
    // 左边的文字颜色
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:leftString attributes:@{NSForegroundColorAttributeName:[UIColor cz_colorWithRed:39 green:133 blue:197],NSFontAttributeName:[UIFont systemFontOfSize:14.0]}];
    
    // 右边的文字颜色
    NSMutableAttributedString *rightS = [[NSMutableAttributedString alloc]initWithString:rightString attributes:@{NSForegroundColorAttributeName:[UIColor cz_colorWithRed:39 green:133 blue:197],NSFontAttributeName:[UIFont systemFontOfSize:19.0]}];
    [string insertAttributedString:rightS atIndex:string.length];
    contentLabel.attributedText = string;
}
- (void)liBtnClick{
    // 立即提现
    VKReManagerCashController *cashVC = [[VKReManagerCashController alloc]init];
    [self presentViewController:cashVC animated:YES completion:nil];
}
- (void)backAction{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)setupDataArray{
    
}

- (void)buttonItemClick{
    VKReNextLevelController *nlVC = [[VKReNextLevelController alloc]init];
    [self presentViewController:nlVC animated:YES completion:nil];
}
-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
@end
